package com.wits.platform.service;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Component;

import com.wits.platform.common.utils.StringUtil;
import com.wits.platform.dao.ResourceDao;
import com.wits.platform.entity.Resource;
import com.wits.platform.entity.Role;

@Component
public class ResourceService extends BaseService<Resource,String>{

	
	private ResourceDao resourceDao;
	
	@javax.annotation.Resource
	public void setResourceDao(ResourceDao resourceDao) {
		this.baseDao=resourceDao;
		this.resourceDao = resourceDao;
	}



	public void deleteInBatch(String ids) {
		List<Resource> list=this.findAll(Arrays.asList(StringUtil.split(ids,",")));
		List<Role> roles=null;
		for(Resource r : list){
			roles=r.getRoles();
			for(Role role :roles){
				role.removeResource(r);
			}
		}
		resourceDao.delete(list);
	}
	
}
